package com.itheima.health.config;

import com.itheima.health.common.EncodingIdConst;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.HashMap;
import java.util.Map;

/**
 * @Project_Name: itcast_health
 * @package_name: com.itheima.health.config
 * @Author: Boyang
 * @Date: 2021/3/13 10:06
 */
public class MyPassEncoderFactories {

    /**
     * @Author: boyang
     * @Date: 10:37 2021/3/13
     * @Param: [encodingId]
     * @ReturnType: org.springframework.security.crypto.password.PasswordEncoder
     * @Description: 支持md5 bcrypt 有前缀和无前缀的密码加密以及解密
     */
    public static PasswordEncoder createMyPasswordEncoder(String encodingId ) {
        Map<String, PasswordEncoder> encoders = new HashMap<>();
        encoders.put(EncodingIdConst.MD5_NO_PRE, new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
        encoders.put(EncodingIdConst.MD5, new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
        encoders.put(EncodingIdConst.BCRYPT, new BCryptPasswordEncoder());
        encoders.put(EncodingIdConst.BCRYPT_NO_PRE, new BCryptPasswordEncoder());
        return new MyPassEncoder(encodingId, encoders);
    }

    private MyPassEncoderFactories() {

    }
}
